package shop.tagHandler;

import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import shop.DAO.OffersDAO;
import shop.bean.OfferBean;

public class productList extends SimpleTagSupport{
	
	public void doTag() throws JspException { 

		// Code to get Products
		Collection<OfferBean> productList = OffersDAO.getOffers();
		//Walk through products ArrayList and get Bean for Bean, --> 
		Iterator<OfferBean> i = productList.iterator();
		while (i.hasNext()){
			try {
				OfferBean offer = new OfferBean();
				offer = i.next();
				getJspContext().setAttribute("id", offer.getId()); 
				getJspContext().setAttribute("name", offer.getName()); 
				getJspContext().setAttribute("description", offer.getDescription()); 
				if(offer.getCountry() == 0)
					getJspContext().setAttribute("country", "Germany");
				else
					getJspContext().setAttribute("country", "France");
				getJspContext().setAttribute("region", offer.getRegion()); 
				getJspContext().setAttribute("price", offer.getPrice());
				getJspContext().setAttribute("quantity", offer.getQuantity());
				// Process the body 
				getJspBody().invoke(null);
			} catch (IOException e) { 
				throw new JspException("Exception processing body");

			}
		} 
	}
}